package no.group.gowther.rest;

import com.fasterxml.jackson.databind.JsonNode;
import no.group.gowther.rest.vo.FilingDetailVO;
import no.group.gowther.rest.vo.Result;
import no.group.gowther.service.FilingService;
import no.group.gowther.service.dto.param.FileFilingDetailQueryDTO;
import no.group.gowther.service.dto.param.FilingDetailQueryDTO;
import no.group.gowther.service.dto.param.OnePieceFilingDetailQueryDTO;
import no.group.gowther.service.dto.FilingDetailDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/filing")
public class FilingRestController {

    @Autowired
    private FilingService filingService;

    @PostMapping("detail")
    public Result<FilingDetailVO> queryFileDetail(@Validated @RequestBody JsonNode param) {
        FilingDetailQueryDTO queryDTO = null;
        if (FileFilingDetailQueryDTO.isMine(param)) {
            queryDTO = FileFilingDetailQueryDTO.getInstance(param);
        } else if (OnePieceFilingDetailQueryDTO.isMine(param)) {
            queryDTO = OnePieceFilingDetailQueryDTO.getInstance(param);
        }
        FilingDetailDTO filingDetail = filingService.getFilingDetail(queryDTO);
        return Result.success(new FilingDetailVO(filingDetail));
    }
}
